package com.leetCode;

/**
 * Description:
 * Copyright:   Copyright (c)2019
 * Company:     zefu
 *
 * @author: 张李鑫
 * @version: 1.0
 * Create at:   2021-10-27 12:19:51
 * <p>
 * Modification History:
 * Date         Author      Version     Description
 * ------------------------------------------------------------------
 * 2021-10-27     张李鑫                     1.0         1.0 Version
 */
public class MergeArr {

    public void merge(int[] nums1, int m, int[] nums2, int n) {
        int[] arr = new int[m+n];
        int leftIndex = 0;
        int rightIndex = 0;
        int index = 0;
        while (leftIndex < m && rightIndex < n) {
            arr[index++] = nums1[leftIndex] < nums2[rightIndex] ? nums1[leftIndex++] : nums2[rightIndex++];
        }

        while (leftIndex < m) {
            arr[index++] = nums1[leftIndex++];
        }
        while (rightIndex < n) {
            arr[index++] = nums2[rightIndex++];
        }
        for (int i = 0; i < arr.length; i++) {
            nums1[i] = arr[i];
        }
    }
}
